#!/usr/bin/env python3

from tkinter import *
from tkinter import ttk
from tkinter.tix import Tk, Control, ComboBox  #升级的组合控件包
from tkinter.messagebox import showinfo, showwarning, showerror,askokcancel #各种类型的提示框
import cookiebrowser

class UI():
    def __init__(self):
        self.root = Tk() # 初始化Tk()
        self.cookie = StringVar()
        self.url = StringVar()
        self.domain = StringVar()
        self.__paint()



    def __paint(self):
        self.root.title("cookie浏览器")    # 设置窗口标题
        #self.root.iconbitmap('1.ico')
        self.root.geometry("800x650")    # 设置窗口大小 注意：是x 不是*
        self.root.resizable(width=True, height=True) # 设置窗口是否可以变化长/宽，False不可变，True可变，默认为True
        self.root.tk.eval('package require Tix')  #引入升级包，这样才能使用升级的组合控件
        self.menubar = None

        row = 0
        frame = LabelFrame(self.root, text="配置参数", labelanchor="nw")
        frame.pack(padx = 10, pady=10, ipadx=5, ipady = 5 )
        colum = 0
        Label(frame, text='cookies:').grid(row = row, column = colum)
        colum+=1
        Entry(frame, textvariable=self.cookie, width = 100).grid(row = row, column = colum)
        row += 1
        colum = 0
        Label(frame, text='url:').grid(row = row, column = colum)
        colum+=1
        Entry(frame, textvariable=self.url, width = 100).grid(row = row, column = colum)
        row += 1
        colum = 0
        Label(frame, text='domain:').grid(row = row, column = colum)
        colum+=1
        Entry(frame, textvariable=self.domain, width = 20).grid(row = row, column = colum, sticky=W)
        row += 1
        ttk.Button(frame,text ="开始", command = self.browse).grid(row=row, column=0)


    def show(self):
        self.root.mainloop()

    def browse(self):
        print(self.url.get())
        print(self.cookie.get())
        print(self.domain.get())
        cookiebrowser.go(self.url.get(), self.cookie.get(), self.domain.get())

if __name__ == "__main__":
    ui = UI()
    ui.show()
